package com.rdxer.core.utils.search;

public enum WhereOperator {

    //equle : filed = value
    equle("="),
    //gt / greaterThan : filed > value
    greaterThan(">"),
    //lt / lessThan : filed < value
    lessThan("<"),
    //ge / greaterThanOrEqualTo : filed >= value
    greaterThanOrEqualTo(">="),
    //le / lessThanOrEqualTo: filed <= value
    lessThanOrEqualTo("<="),
    //notEqule : filed != value
    notEqule("!="),
    notEqule2("<>"),
    //like : filed like value
    like("like"),
    //notLike : filed not like value
    notLike("not like"),
    notLike2("notLike"),

    //                cb.isNotNull()
    //                cb.isNull()
    //                cb.isTrue()
    //                cb.isFalse()
    isNotNull("isNotNull"),
    isNull("isNull"),
    isTrue("isTrue"),
    isFalse("isFalse"),


    in("in");

    private final String operator;
    private Object value;

    WhereOperator(String operator) {
        this.operator = operator;
    }

    public static WhereOperator parse(String opt, Object value) {
        WhereOperator parse = parse(opt);
        if (parse != null) {
            parse.setValue(value);
        }
        return parse;
    }

    public static WhereOperator parse(String opt) {
        if (WhereOperator.equle.operator.equals(opt)) return WhereOperator.equle;
        if (WhereOperator.greaterThan.operator.equals(opt)) return WhereOperator.greaterThan;
        if (WhereOperator.lessThan.operator.equals(opt)) return WhereOperator.lessThan;
        if (WhereOperator.greaterThanOrEqualTo.operator.equals(opt)) return WhereOperator.greaterThanOrEqualTo;
        if (WhereOperator.lessThanOrEqualTo.operator.equals(opt)) return WhereOperator.lessThanOrEqualTo;
        if (WhereOperator.notEqule.operator.equals(opt)) return WhereOperator.notEqule;
        if (WhereOperator.notEqule2.operator.equals(opt)) return WhereOperator.notEqule2;
        if (WhereOperator.like.operator.equals(opt)) return WhereOperator.like;
        if (WhereOperator.notLike.operator.equals(opt)) return WhereOperator.notLike;
        if (WhereOperator.notLike2.operator.equals(opt)) return WhereOperator.notLike2;

        if (WhereOperator.isNotNull.operator.equals(opt)) return WhereOperator.isNotNull;
        if (WhereOperator.isNull.operator.equals(opt)) return WhereOperator.isNull;
        if (WhereOperator.isTrue.operator.equals(opt)) return WhereOperator.isTrue;
        if (WhereOperator.isFalse.operator.equals(opt)) return WhereOperator.isFalse;

        if (WhereOperator.in.operator.equals(opt)) return WhereOperator.in;



        return null;
    }

    public Object getValue() {
        return value;
    }

    public WhereOperator setValue(Object value) {
        this.value = value;
        return this;
    }
}